package com.mlnx.web.ui.controller;

import com.mlnx.ui.entity.Patient;
import com.mlnx.ui.pojo.vo.SportWayVO;
import com.mlnx.ui.pojo.vo.WalkReportVO;
import com.mlnx.ui.service.PatientService;
import com.mlnx.ui.service.SportWayService;
import com.mlnx.ui.service.WalkReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Api(value = "UI报告接口", tags = {"UI报告接口"})
@Controller
public class ViewController {
    @Autowired
    private SportWayService sportWayService;

    @Autowired
    private WalkReportService walkReportService;

    @Autowired
    private PatientService patientService;


    @ApiOperation(value = "通过患者ID获取6分钟报告")
    @RequestMapping("/six_walk")
    public String showSixwalk(Integer patientId, Model model) {
        List<WalkReportVO> walkReportVOList = walkReportService.getSixWalkReports(patientId);
        Patient patient = patientService.getById(patientId);

        if (walkReportVOList != null && walkReportVOList.size() > 0)
            model.addAttribute("reportList", walkReportVOList);

        model.addAttribute("patient", patient);

        return "six_walk";
    }

    @ApiOperation(value = "通过患者ID获取血压报告报告")
    @RequestMapping("/bp_history")
    public String bp_history(Integer patientId, Model model) {
        Patient patient = patientService.getById(patientId);
        try {
//            List<BpAvg> lastLastWeek = dubboConsumerService.bpService.getLastLastWeekBpAvg(patientId);
//            List<BpAvg> lastWeek = dubboConsumerService.bpService.getLastWeekBpAvg(patientId);
            model.addAttribute("lastLastWeek", null);
            model.addAttribute("lastWeek", null);
        } catch (Exception e) {
            e.printStackTrace();
        }

        model.addAttribute("patient", patient);
        return "bp_history";
    }

    @ApiOperation(value = "通过患者ID获取康复运动处方")
    @RequestMapping("/rehabilitation")
    public String showRehabilitation(@RequestParam("patientId") Integer patientId, Model model) {
        List<SportWayVO> sportWayVOList = sportWayService.getSportPrescriptions(patientId);
        model.addAttribute("list", sportWayVOList);
        model.addAttribute("patientId", patientId);
        return "run_ecg";
    }


    @ApiOperation(value = "通过患者ID获取历史血糖报告")
    @RequestMapping("/bg_history")
    public String bg_history(Integer patientId, Model model) {

        model.addAttribute("patientId", patientId);
        return "bg_history";
    }
}
